//
//  InTrainingModel.swift
//  DaRings
//
//  Created by 尹琼 on 2022/11/29.
//

import UIKit
import MYModule
import HandyJSON

open class InTrainingModel: NSObject, HandyJSON {
    
    /// 设置目标 item
    public var targetItem: TrainingItemModel?
    
    /// 时间/距离 item
    public var viceItem: TrainingItemModel?
    
    /// 其他子item
    public var items: [TrainingItemModel] = []
    
    
    required public override init() {}
    
    
}

extension InTrainingModel {
    
    public var subItems: [TrainingItemModel] {
        
        var items = [TrainingItemModel]()
        if let targetItem = targetItem {
            items.append(targetItem)
        }
        if let timeItem = viceItem {
            items.append(timeItem)
        }
        
        items.append(contentsOf: self.items)
        
        return items
        
    }
    
    public var targetAttriText: NSMutableAttributedString? {
        
        guard let item = self.targetItem else {
            return nil
        }
        
        let targetFontSize: CGFloat = (item.contentType == .time && item.targetData != nil) ? 50 : 70
        let attriText = item.currentDataTitle.toAttributed
            .foregroundColor(UIColor.assist_222222)
            .font(Fonts.boldSystemFont(ofSize: targetFontSize))
            .rawValue
        
        
        if let targetDataTitle = item.targetDataTitle {
            
            attriText.append("/\(targetDataTitle)".toAttributed
                .foregroundColor(UIColor.assist_222222)
                .font(Fonts.systemFont(ofSize: 20))
                .rawValue)
        }
        
        if item.contentType != .pace && item.contentType != .time {
            if let unit = item.unit {
                
                attriText.append(unit.language
                    .toAttributed
                    .foregroundColor(UIColor.assist_222222)
                    .font(Fonts.systemFont(ofSize: 20))
                    .rawValue)
            }
        }
        
        return attriText
        
    }
    
}
